package com.bkgy.modular.alarm.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bkgy.modular.alarm.entity.*;
import com.bkgy.modular.tbdsjruleedit.service.TbDsjRuleEditService;
import com.bkgy.modular.tbdsjwarninginformation.dao.TbDsjWarningInformationDao;
import com.bkgy.modular.tbdsjwarninginformation.entity.TbDsjWarningInformation;
import com.bkgy.sys.common.entity.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * 1720报警
 */
@Service
@Slf4j
public class AlarmService1720 {

    @Resource
    private TbDsjWarnRuleEdit1Service tbDsjWarnRuleEdit1Service;

    @Resource
    private TbDsjWarningInformationDao tbDsjWarningInformationDao;

    @Resource
    private RestTemplate restTemplate;

    @Resource
    private TbDsjRuleEditService tbDsjRuleEditService;

    //报警内容
    private static List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1s;
    //报警内容1秒
    private static List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1s1;
    private static List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1s2;
    //报警内容30秒
    private static List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1s30;
    //报警内容300秒
//    private static List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1s300;
    //报警记录限制
    private static List<TbDsjWarnRuleEdit1> record;
    //一定内刷新总记录(分钟)
    private static Long timeLimit = 1L;
    //一定内语音报警总记录限制
    private static Integer recordLimit = 10;
    //一定内语音报警单个限制
    private static Integer sameLimit = 2;

    private static String topCoilid31 = "";
    private static String topCoilid32 = "";

    private static List<String> list = new ArrayList<>();

    // 采集的点值集合
    private static List<Double> list2 = new ArrayList<>();

    /**
     * 1秒周期报警
     */
    //@Scheduled(cron = "${cronTime4}")//定时在112全打开，113，115全部关闭
    public void startAlarm1() {
        try {
            //log.error("AlarmService1720+startAlarm1");
            if (!isStart()) {
                return;
            }
            //初始化变量
            initObj();
            //获取根据变量名称去重后的属性
            List<String> collectName = tbDsjWarnRuleEdit1s1.stream().map(TbDsjWarnRuleEdit1::getWarning_l1_variable_name).distinct().collect(Collectors.toList());
            List<String> collect = tbDsjWarnRuleEdit1s2.stream().map(TbDsjWarnRuleEdit1::getWarning_l1_variable_name).distinct().collect(Collectors.toList());
            //        List<TbDsjWarnRuleEdit1> collect = tbDsjWarnRuleEdit1s1.stream().filter(distinctByKey(TbDsjWarnRuleEdit1::getWarning_l1_variable_name)).collect(Collectors.toList());
            // 中间件获取焊缝到达各机架信号点
            list.add("C621_N10161_2");
            list.add("C621_N10161_4");
            list.add("C621_N10161_6");
            list.add("C621_N10161_8");

            //根据变量名从中间件获取实时值
            HMIResponse dataByHMI = getDataByHMI(collectName);
            List<HMIResult> results = dataByHMI.getResults();
            HMIResponse dataByHMI1 = getDataByHMI(collect);
            List<HMIResult> results1 = dataByHMI1.getResults();

            HMIResponse dataByHMI2 = getDataByHMI(list);
            List<HMIResult> results2 = dataByHMI2.getResults();

            //报警
            alarmAll(tbDsjWarnRuleEdit1s1, results);
            callThePolice(tbDsjWarnRuleEdit1s2, results1, results2);

        } catch (Exception e) {
            log.error("1720的1秒周期报警，错误日志:");
            //log.error(e.getMessage());
        }
    }

    /**
     * 30秒周期报警
     */
    //@Scheduled(cron = "${cronTime5}")//定时在112全打开，113，115全部关闭
    public void startAlarm30() {
        try {
            //log.error("AlarmService1720+startAlarm30");
            if (!isStart()) {
                return;
            }
            //初始化变量
            initObj();
            //获取根据变量名称去重后的属性
            List<String> collectName = tbDsjWarnRuleEdit1s30.stream().map(TbDsjWarnRuleEdit1::getWarning_l1_variable_name).distinct().collect(Collectors.toList());
//        List<TbDsjWarnRuleEdit1> collect = tbDsjWarnRuleEdit1s1.stream().filter(distinctByKey(TbDsjWarnRuleEdit1::getWarning_l1_variable_name)).collect(Collectors.toList());
            //根据变量名从中间件获取实时值
            HMIResponse dataByHMI = getDataByHMI(collectName);
            List<HMIResult> results = dataByHMI.getResults();
            //报警
            alarmAll(tbDsjWarnRuleEdit1s30, results);
        } catch (Exception e) {
            log.info("1720的30秒周期报警，错误日志:");
            log.info(e.getMessage());
        }
    }

    /**
     * 300秒周期报警
     */
//     (cron = "${cronTime6}")//定时在112全打开，113，115全部关闭
//    public void startAlarm300() {
//       try {
//           if (!isStart()) {
//               return;
//           }
//           //初始化变量
//           initObj();
//           //获取根据变量名称去重后的属性
//           List<String> collectName = tbDsjWarnRuleEdit1s300.stream().map(TbDsjWarnRuleEdit1::getWarning_l1_variable_name).distinct().collect(Collectors.toList());
////        List<TbDsjWarnRuleEdit1> collect = tbDsjWarnRuleEdit1s1.stream().filter(distinctByKey(TbDsjWarnRuleEdit1::getWarning_l1_variable_name)).collect(Collectors.toList());
//           //根据变量名从中间件获取实时值
//           HMIResponse dataByHMI = getDataByHMI(collectName);
//           List<HMIResult> results = dataByHMI.getResults();
//           //报警
//           alarmAll(tbDsjWarnRuleEdit1s300,results);
//       }catch (Exception e){
//           log.info("1720的30秒周期报警，错误日志:");
//           log.info(e.getMessage());
//       }
//    }


    /**
     * 初始化各种报警对象
     */
    private void initObj() {
        if (CollectionUtils.isEmpty(tbDsjWarnRuleEdit1s)) {
            tbDsjWarnRuleEdit1s = tbDsjWarnRuleEdit1Service.list();
            tbDsjWarnRuleEdit1s1 = tbDsjWarnRuleEdit1s.stream().filter(t -> t.getSample_frequency() == 1).collect(Collectors.toList());
            tbDsjWarnRuleEdit1s2 = tbDsjWarnRuleEdit1s.stream().filter(t -> t.getSample_frequency() == 2).collect(Collectors.toList());
            tbDsjWarnRuleEdit1s30 = tbDsjWarnRuleEdit1s.stream().filter(t -> t.getSample_frequency() == 30).collect(Collectors.toList());
//            tbDsjWarnRuleEdit1s300 = tbDsjWarnRuleEdit1s.stream().filter(t -> t.getSample_frequency() == 300).collect(Collectors.toList());
        }
    }

    /**
     * 判断是否停机
     *
     * @return
     */
    private Boolean isStart() {
        try {
            List<String> list = new ArrayList<>();
            list.add("C621_VM_MDV_01_4VFB");
            HMIResponse dataByHMI = getDataByHMI(list);
            if (dataByHMI.getResults().get(0).getValue() < 200) {
                return false;
            }
            return true;
        } catch (Exception e) {
            log.error("AlarmService1720:isStart执行失败！！");
            return false;
        }
    }

    /**
     * 去重
     *
     * @param keyExtractor
     * @param <T>
     * @return
     */
    private <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
        Map<Object, Boolean> map = new ConcurrentHashMap<>();
        return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }

    /**
     * 批量从中间件获取变量值
     *
     * @return
     */
    private HMIResponse getDataByHMI(List<String> tagList) {
        HMIRequest hmiRequest = new HMIRequest();
        hmiRequest.setAction("get_tags");
        hmiRequest.setOperator("abc");//可以随意指定
        hmiRequest.setTerminal("FM_01");//可以随意指定
        ArrayList<HMIBody> list = new ArrayList<>();
        for (String tagName : tagList) {
            HMIBody hmiBody = new HMIBody();
            hmiBody.setTagName(tagName);//变量名
            hmiBody.setTimestamp(0);//时间周期默认填写0
            list.add(hmiBody);
        }
        hmiRequest.setBody(list);
        HMIResponse hmiResponse = restTemplate.postForObject("http://170.0.200.112:8088/HMI", JSONObject.toJSONString(hmiRequest), HMIResponse.class);
        return hmiResponse;
    }

    /**
     * 批量中间件赋值
     */
    private void setDataToHMI(List<HMIDataUpdate.UpdateBody.AlarmPop> alarmPops) {
        HMIDataUpdate hmiDataUpdate = new HMIDataUpdate();
        hmiDataUpdate.setAction("set_tags");
        hmiDataUpdate.setOperator("abc");
        hmiDataUpdate.setTerminal("FM_01");
        HMIDataUpdate.UpdateBody updateBody = new HMIDataUpdate.UpdateBody();
        updateBody.setAlarm_pop(alarmPops);
        hmiDataUpdate.setBody(updateBody);
        restTemplate.postForObject("http://170.0.200.112:8088/HMI", JSONObject.toJSONString(hmiDataUpdate), Object.class);
    }

    /**
     * 查询卷号
     *
     * @param deviceCode
     * @return
     */
    private String findCoilId(String deviceCode) {
        String coilId = null;
        Map<String, String> map = new HashMap<>();
        map.put("Shear", "zone0");
        map.put("TL", "zone12");
        map.put("PL1", "zone13");
        map.put("PL2", "zone14");
        map.put("PL3", "zone15");
        map.put("PL4", "zone16");
        map.put("RINSE4", "zone17");
        map.put("EnS1", "zone30");
        map.put("S1S2", "zone31");
        map.put("S1", "zone31");
        map.put("S2S3", "zone32");
        map.put("S2", "zone32");
        map.put("S3S4", "zone33");
        map.put("S3", "zone33");
        map.put("ExS4", "zone34");
        map.put("S4", "zone34");
        try {
            if (!StringUtils.isEmpty(deviceCode)) {
                String zone = map.get(deviceCode);
                if (!StringUtils.isEmpty(zone)) {
                    String data = restTemplate.postForObject("http://170.0.200.11:8090/restapii?name=C621_zonetrk", null, String.class);
                    JSONObject jsonObject = JSONObject.parseObject(data);
                    JSONArray zone_row = jsonObject.getJSONArray("zone_row");
                    List<ZoneEntity> list = JSONObject.parseArray(zone_row.toString(), ZoneEntity.class);
                    ZoneEntity zoneEntity = list.stream().filter(t -> t.getZONENO().equalsIgnoreCase(zone)).findFirst().orElse(null);
                    if (!ObjectUtils.isEmpty(zoneEntity)) {
                        coilId = zoneEntity.getCoilid();
                    }
                }
            }
        } catch (Exception e) {
            log.info("Zone获取失败");
            e.printStackTrace();
        }
        return coilId;
    }

    /**
     * 语音报警
     *
     * @param tbDsjWarnRuleEdit1
     */
    private void voiceAlarm(TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1) {
        JSONObject object = new JSONObject();
        object.put("Sender", "java");
        object.put("msg", tbDsjWarnRuleEdit1.getWarning_content() + tbDsjWarnRuleEdit1.getThreshold_value().intValue());
        object.put("tag_name", "alarm1720");
        object.put("times", "2");
//        restTemplate.postForObject("http://170.0.200.112:1235/voice_alarm_HMI", object.toJSONString(), Object.class);
    }

    /**
     * 报警逻辑
     *
     * @param tbDsjWarnRuleEdit1All 报警规则
     * @param results               变量实时值
     */
    private void alarmAll(List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1All, List<HMIResult> results) {
        try {
            //报警信息临时
            List<HMIDataUpdate.UpdateBody.AlarmPop> alarmPops = new ArrayList<>();

            //根据规则进行判断是否报警
            results.forEach(t -> {
                List<TbDsjWarnRuleEdit1> ruleEdits = tbDsjWarnRuleEdit1All.stream().filter(x -> x.getWarning_l1_variable_name().equals(t.getTagName())).collect(Collectors.toList());
                //根据大于小于分组
                Map<String, List<TbDsjWarnRuleEdit1>> ruleByEditor = ruleEdits.stream().collect(Collectors.groupingBy(TbDsjWarnRuleEdit1::getRule_editor));
                ruleByEditor.forEach((k, v) -> {
                    if (k.equals(">")) {
                        //根据阈值进行大到小排序
                        List<TbDsjWarnRuleEdit1> orderList = v.stream().sorted(Comparator.comparing(TbDsjWarnRuleEdit1::getThreshold_value, Comparator.reverseOrder())).collect(Collectors.toList());
                        for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : orderList) {
                            if (t.getValue() > tbDsjWarnRuleEdit1.getThreshold_value().doubleValue()) {

                                HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                alarmPop.setWarningGrade(tbDsjWarnRuleEdit1.getWarning_grade());
                                alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                //添加到临时报警信息，准备存入中间件
                                alarmPops.add(alarmPop);
                                //判断语音报警
                                if (tbDsjWarnRuleEdit1.getWarning_grade() == 2) {
                                    if (CollectionUtils.isEmpty(record)) {
                                        record = new ArrayList<>();
                                        record.add(tbDsjWarnRuleEdit1);
                                        voiceAlarm(tbDsjWarnRuleEdit1);
                                    } else {
                                        //判断第一条语音报警是否在两分钟以内
                                        boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                        //统计相同语音报警次数
                                        long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                        //判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                        if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                            record.add(tbDsjWarnRuleEdit1);
//                                            voiceAlarm(tbDsjWarnRuleEdit1);
                                        }
                                        //当超过两分钟时刷新临时记录
                                        if (!timeOK) {
                                            record.clear();
                                            record.add(tbDsjWarnRuleEdit1);
//                                            voiceAlarm(tbDsjWarnRuleEdit1);
                                        }
                                    }
                                }

                                //保存记录到数据库
                                TbDsjWarningInformation information = new TbDsjWarningInformation();
                                information.setWarning_cacl_result(tbDsjWarnRuleEdit1.getWarning_cacl_result());
                                information.setL1_variable_name(tbDsjWarnRuleEdit1.getWarning_l1_variable_name());
                                information.setL1_variable_value(t.getValue());
                                information.setWarning_grade(tbDsjWarnRuleEdit1.getWarning_grade().doubleValue());
                                information.setWarning_content(tbDsjWarnRuleEdit1.getWarning_content());
                                information.setWarning_suggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                information.setProcess_rule_variable(tbDsjWarnRuleEdit1.getProcess_rule_variable());
                                information.setThreshold_value(tbDsjWarnRuleEdit1.getThreshold_value().doubleValue());
                                information.setMonitoring_cycle(tbDsjWarnRuleEdit1.getSample_frequency().doubleValue());
                                information.setArea_code(tbDsjWarnRuleEdit1.getArea_code());
                                information.setDevice_code(tbDsjWarnRuleEdit1.getDevice_code());
                                String coilId = findCoilId(tbDsjWarnRuleEdit1.getDevice_code());
                                information.setCoil_id(coilId);
                                information.setCreate_time(new Timestamp(new Date().getTime()));
                                tbDsjWarningInformationDao.insert(information);
                                return;
                            }
                        }
                    }

                    if (k.equals("<")) {
                        //根据阈值进行小到大排序
                        List<TbDsjWarnRuleEdit1> orderList = v.stream().sorted(Comparator.comparing(TbDsjWarnRuleEdit1::getThreshold_value)).collect(Collectors.toList());
                        for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : orderList) {
                            if (t.getValue() < tbDsjWarnRuleEdit1.getThreshold_value().doubleValue()) {

                                HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                alarmPop.setWarningGrade(tbDsjWarnRuleEdit1.getWarning_grade());
                                alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                //添加到临时报警信息，准备存入中间件
                                alarmPops.add(alarmPop);
                                //判断语音报警
                                if (tbDsjWarnRuleEdit1.getWarning_grade() == 2) {
                                    if (CollectionUtils.isEmpty(record)) {
                                        record = new ArrayList<>();
                                        record.add(tbDsjWarnRuleEdit1);
                                        voiceAlarm(tbDsjWarnRuleEdit1);
                                    } else {
                                        //判断第一条语音报警是否在两分钟以内
                                        boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                        //统计相同语音报警次数
                                        long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                        //判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                        if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                            record.add(tbDsjWarnRuleEdit1);
//                                            voiceAlarm(tbDsjWarnRuleEdit1);
                                        }
                                        //当超过两分钟时刷新临时记录
                                        if (!timeOK) {
                                            record.clear();
                                            record.add(tbDsjWarnRuleEdit1);
//                                            voiceAlarm(tbDsjWarnRuleEdit1);
                                        }
                                    }
                                }

                                //保存记录到数据库
                                TbDsjWarningInformation information = new TbDsjWarningInformation();
                                information.setWarning_cacl_result(tbDsjWarnRuleEdit1.getWarning_cacl_result());
                                information.setL1_variable_name(tbDsjWarnRuleEdit1.getWarning_l1_variable_name());
                                information.setL1_variable_value(t.getValue());
                                information.setWarning_grade(tbDsjWarnRuleEdit1.getWarning_grade().doubleValue());
                                information.setWarning_content(tbDsjWarnRuleEdit1.getWarning_content());
                                information.setWarning_suggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                information.setProcess_rule_variable(tbDsjWarnRuleEdit1.getProcess_rule_variable());
                                information.setThreshold_value(tbDsjWarnRuleEdit1.getThreshold_value().doubleValue());
                                information.setMonitoring_cycle(tbDsjWarnRuleEdit1.getSample_frequency().doubleValue());
                                information.setArea_code(tbDsjWarnRuleEdit1.getArea_code());
                                information.setDevice_code(tbDsjWarnRuleEdit1.getDevice_code());
                                String coilId = findCoilId(tbDsjWarnRuleEdit1.getDevice_code());
                                information.setCoil_id(coilId);
                                information.setCreate_time(new Timestamp(new Date().getTime()));
                                tbDsjWarningInformationDao.insert(information);
                                return;
                            }
                        }
                    }
                    if (k.equals("=")) {
                        //根据阈值进行小到大排序
                        for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : v) {
                            if (t.getValue() == tbDsjWarnRuleEdit1.getThreshold_value().doubleValue()) {

                                HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                alarmPop.setWarningGrade(tbDsjWarnRuleEdit1.getWarning_grade());
                                alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                //添加到临时报警信息，准备存入中间件
                                alarmPops.add(alarmPop);
                                //判断语音报警
                                if (tbDsjWarnRuleEdit1.getWarning_grade() == 2) {
                                    if (CollectionUtils.isEmpty(record)) {
                                        record = new ArrayList<>();
                                        record.add(tbDsjWarnRuleEdit1);
                                        voiceAlarm(tbDsjWarnRuleEdit1);
                                    } else {
                                        //判断第一条语音报警是否在两分钟以内
                                        boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                        //统计相同语音报警次数
                                        long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                        //判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                        if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                            record.add(tbDsjWarnRuleEdit1);
//                                            voiceAlarm(tbDsjWarnRuleEdit1);
                                        }
                                        //当超过两分钟时刷新临时记录
                                        if (!timeOK) {
                                            record.clear();
                                            record.add(tbDsjWarnRuleEdit1);
//                                            voiceAlarm(tbDsjWarnRuleEdit1);
                                        }
                                    }
                                }

                                //保存记录到数据库
                                TbDsjWarningInformation information = new TbDsjWarningInformation();
                                information.setWarning_cacl_result(tbDsjWarnRuleEdit1.getWarning_cacl_result());
                                information.setL1_variable_name(tbDsjWarnRuleEdit1.getWarning_l1_variable_name());
                                information.setL1_variable_value(t.getValue());
                                information.setWarning_grade(tbDsjWarnRuleEdit1.getWarning_grade().doubleValue());
                                information.setWarning_content(tbDsjWarnRuleEdit1.getWarning_content());
                                information.setWarning_suggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                information.setProcess_rule_variable(tbDsjWarnRuleEdit1.getProcess_rule_variable());
                                information.setThreshold_value(tbDsjWarnRuleEdit1.getThreshold_value().doubleValue());
                                information.setMonitoring_cycle(tbDsjWarnRuleEdit1.getSample_frequency().doubleValue());
                                information.setArea_code(tbDsjWarnRuleEdit1.getArea_code());
                                information.setDevice_code(tbDsjWarnRuleEdit1.getDevice_code());
                                String coilId = findCoilId(tbDsjWarnRuleEdit1.getDevice_code());
                                information.setCoil_id(coilId);
                                information.setCreate_time(new Timestamp(new Date().getTime()));
                                tbDsjWarningInformationDao.insert(information);
                                return;
                            }
                        }
                    }
                });
            });
            setDataToHMI(alarmPops);
        } catch (Exception e) {
            log.info("报警逻辑1720，错误日志:");
            log.info(e.getMessage());
        }
    }

    public void callThePolice(List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1All, List<HMIResult> results, List<HMIResult> results2) {
        String zoneno31 = null;
        String zoneno32 = null;
        String coilid31 = null;
        String coilid32 = null;
        //报警信息临时
        List<HMIDataUpdate.UpdateBody.AlarmPop> alarmPops = new ArrayList<>();
        ResultData dataTbDsjRuleEditshi621 = tbDsjRuleEditService.findDataTbDsjRuleEditshi621();
        List<ZoneEntity> data = (List<ZoneEntity>) dataTbDsjRuleEditshi621.getData();
        for (ZoneEntity item : data) {
            if (item.getZONENO().equals("ZONE31")) {
                zoneno31 = item.getZONENO();
                coilid31 = item.getCoilid();
            } else if (item.getZONENO().equals("ZONE32")) {
                zoneno32 = item.getZONENO();
                coilid32 = item.getCoilid();
            }
        }
        // 总数
        Double num = 0.0;
        // 平均值
        double avg = 0.0;
        for (HMIResult hmiResult : results2) {
            String hmiResultTagName = hmiResult.getTagName();
            if (hmiResultTagName.equals("C621_N10161_2")) {
                // 焊缝等于1.0的时候
                if (!topCoilid31.equals(coilid31)) {
                    // 清空上一卷的数据
                    list2.clear();
                    topCoilid31 = coilid31;
                    topCoilid32 = coilid32;
                } else {
                    for (HMIResult result : results) {
                        String tagName = result.getTagName();
                        // 轧制力
                        if (tagName.equals("C621_WP1FBCRT")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s1_force_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s1_force_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    // 偏差大于阈值的时候
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // 工作辊
                        if (tagName.equals("C621_WFW1BNDFB")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s1_wr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s1_wr_bendforce_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // 中间辊
                        if (tagName.equals("C621_WFI1BNDFB")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s1_mr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s1_mr_bendforce_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
                                                    //                                                  voiceAlarm(tbDsjWarnRuleEdit1);

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    topCoilid31 = coilid31;
                    topCoilid32 = coilid32;
                }
            } else if (hmiResultTagName.equals("C621_N10161_4")) {
                // 焊缝等于1.0的时候
                if (!topCoilid32.equals(coilid32)) {
                    // 清空上一卷的数据
                    list2.clear();
                    topCoilid31 = coilid31;
                    topCoilid32 = coilid32;
                } else {
                    for (HMIResult result : results) {
                        String tagName = result.getTagName();
                        getaDouble(tbDsjWarnRuleEdit1All, alarmPops, num, result, tagName);
                    }
                    topCoilid31 = coilid31;
                    topCoilid32 = coilid32;
                }
            }
            /*else if (hmiResultTagName.equals("C621_N10161_6")) {
                // 焊缝等于1.0的时候
                if (hmiResult.getValue() == 1.0) {
                    // 清空上一卷的数据
                    list2.clear();
                } else {
                    for (HMIResult result : results) {
                        String tagName = result.getTagName();
                        // 轧制力
                        if (tagName.equals("C621_WP3FBCRT")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_force_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_force_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // 工作辊
                        if (tagName.equals("C621_WFW3BNDFB")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_wr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_wr_bendforce_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // 中间辊
                        if (tagName.equals("C621_WFI3BNDFB")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_mr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_mr_bendforce_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (hmiResultTagName.equals("C621_N10161_8")) {
                // 焊缝等于1.0的时候
                if (hmiResult.getValue() == 1.0) {
                    // 清空上一卷的数据
                    list2.clear();
                } else {
                    for (HMIResult result : results) {
                        String tagName = result.getTagName();
                        // 轧制力
                        if (tagName.equals("C621_WP4FBCRT")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_force_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_force_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // 工作辊
                        if (tagName.equals("C621_WFW4BNDFB")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_wr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_wr_bendforce_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // 中间辊
                        if (tagName.equals("C621_WFI4BNDFB")) {
                            Double value = result.getValue();
                            // 采集的点值存到集合
                            list2.add(value);
                            // 求总数
                            for (Double aDouble : list2) {
                                num += aDouble;
                            }
                            // 平均值
                            avg = num / list.size() * 1.0;
                            // 求偏差
                            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
                            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_mr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_mr_bendforce_yellow")) {
                                    // 阈值
                                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                                    // 报警等级
                                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                                    // 符号(报警规则)
                                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                                    if (bias > threshold_value.doubleValue()) {
                                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                                        alarmPop.setWarningGrade(warning_grade);
                                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                                        // 添加到临时报警信息，准备存入中间件
                                        alarmPops.add(alarmPop);
                                        if (warning_grade == 2) {
                                            if (CollectionUtils.isEmpty(record)) {
                                                record = new ArrayList<>();
                                                record.add(tbDsjWarnRuleEdit1);
                                                voiceAlarm(tbDsjWarnRuleEdit1);
                                            } else {
                                                // 判断第一条语音报警是否在两分钟以内
                                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                                // 统计相同语音报警次数
                                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                                // 当超过两分钟时刷新临时记录
                                                if (!timeOK) {
                                                    record.clear();
                                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }*/
        }

    }

    /**
     * @param tbDsjWarnRuleEdit1All 报警内容1s集合
     * @param alarmPops             报警信息临时集合
     * @param num                   总数
     * @param result                每条数据
     * @param tagName               每条数据的tagName
     */
    private void getaDouble(List<TbDsjWarnRuleEdit1> tbDsjWarnRuleEdit1All, List<HMIDataUpdate.UpdateBody.AlarmPop> alarmPops, Double num, HMIResult result, String tagName) {
        double avg;// 轧制力
        if (tagName.equals("C621_WP2FBCRT")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s2_force_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s2_force_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
        // 工作辊
        if (tagName.equals("C621_WFW2BNDFB")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s2_wr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s2_wr_bendforce_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
        // 中间辊
        if (tagName.equals("C621_WFI2BNDFB")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s2_mr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s2_mr_bendforce_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }

        // 轧制力
        if (tagName.equals("C621_WP3FBCRT")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_force_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_force_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
        // 工作辊
        if (tagName.equals("C621_WFW3BNDFB")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_wr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_wr_bendforce_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
        // 中间辊
        if (tagName.equals("C621_WFI3BNDFB")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_mr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s3_mr_bendforce_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }

        // 轧制力
        if (tagName.equals("C621_WP4FBCRT")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_force_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_force_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
        // 工作辊
        if (tagName.equals("C621_WFW4BNDFB")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs(list2.get(list2.size() - 1) - avg) / avg;
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_wr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_wr_bendforce_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
        // 中间辊
        if (tagName.equals("C621_WFI4BNDFB")) {
            Double value = result.getValue();
            // 采集的点值存到集合
            list2.add(value);
            // 求总数
            for (Double aDouble : list2) {
                num += aDouble;
            }
            // 平均值
            avg = num / list.size() * 1.0;
            // 求偏差
            double bias = Math.abs((list2.get(list2.size() - 1) - avg) / avg);
            for (TbDsjWarnRuleEdit1 tbDsjWarnRuleEdit1 : tbDsjWarnRuleEdit1All) {
                if (tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_mr_bendforce_red") || tbDsjWarnRuleEdit1.getProcess_rule_variable().equals("s4_mr_bendforce_yellow")) {
                    // 阈值
                    BigDecimal threshold_value = tbDsjWarnRuleEdit1.getThreshold_value();
                    // 报警等级
                    Integer warning_grade = tbDsjWarnRuleEdit1.getWarning_grade();
                    // 符号(报警规则)
                    String rule_editor = tbDsjWarnRuleEdit1.getRule_editor();
                    if (bias > threshold_value.doubleValue()) {
                        HMIDataUpdate.UpdateBody.AlarmPop alarmPop = new HMIDataUpdate.UpdateBody.AlarmPop();
                        alarmPop.setWarningGrade(warning_grade);
                        alarmPop.setDeviceCode(tbDsjWarnRuleEdit1.getDevice_code());
                        alarmPop.setWarningContent(tbDsjWarnRuleEdit1.getWarning_content());
                        alarmPop.setWarningSuggestion(tbDsjWarnRuleEdit1.getWarning_suggestion());
                        // 添加到临时报警信息，准备存入中间件
                        alarmPops.add(alarmPop);
                        if (warning_grade == 2) {
                            if (CollectionUtils.isEmpty(record)) {
                                record = new ArrayList<>();
                                record.add(tbDsjWarnRuleEdit1);
                                voiceAlarm(tbDsjWarnRuleEdit1);
                            } else {
                                // 判断第一条语音报警是否在两分钟以内
                                boolean timeOK = record.get(0).getCreate_time().toLocalDateTime().plusMinutes(timeLimit).isAfter(LocalDateTime.now());
                                // 统计相同语音报警次数
                                long count = record.stream().filter(q -> q.getWarning_l1_variable_name().equals(tbDsjWarnRuleEdit1.getWarning_l1_variable_name())).count();
                                // 判断总记录数小于标准,并且在时间限制内，并且单条报警不超过标准
                                if (record.size() < recordLimit && timeOK && count < sameLimit) {
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                                // 当超过两分钟时刷新临时记录
                                if (!timeOK) {
                                    record.clear();
                                    record.add(tbDsjWarnRuleEdit1);
//                                                  voiceAlarm(tbDsjWarnRuleEdit1);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
